package com.briup.corejava.day20;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * 从data.txt中读取保存的基本类型和字符串
 */
public class Test2_dr {
    public static void main(String[] args) {
        DataInputStream dis = null;
        FileInputStream fis = null;

        try {
            fis = new FileInputStream("src/com/briup/corejava/day20/file/data.txt");
            dis = new DataInputStream(fis);
            // 读取数据，因为是按照字节进行读取的
            // 必须保证读取的顺序就是写入的顺序
            long l = dis.readLong();
            int i = dis.readInt();

            double v = dis.readDouble();
            float v1 = dis.readFloat();
            boolean b = dis.readBoolean();
            char c = dis.readChar();
            String s = dis.readUTF();
            System.out.println("i = " + i);
            System.out.println("l = " + l);
            System.out.println("v = " + v);
            System.out.println("v1 = " + v1);
            System.out.println("b = " + b);
            System.out.println("c = " + c);
            System.out.println("s = " + s);

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            // 自己去关闭
        }
    }
}
